package cn.wetcland.urban.framework.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.wetcland.urban.common.AjaxResponse;
import cn.wetcland.urban.framework.dto.AddressAddDTO;
import cn.wetcland.urban.framework.dto.AddressUpdateDTO;
import cn.wetcland.urban.framework.service.UtCustomerAddressService;
import cn.wetcland.urban.framework.vo.CustomerAddressListItemVO;
import cn.wetcland.urban.generator.domain.UtCustomerAddress;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Resource
    public UtCustomerAddressService utCustomerAddressService;

    @SaCheckLogin
    @PostMapping("/add")
    public AjaxResponse addAddress(@Validated @RequestBody AddressAddDTO addressAddDTO) {
        utCustomerAddressService.addAddress(addressAddDTO);
        return AjaxResponse.success();
    }

    @SaCheckLogin
    @DeleteMapping("/delete/{id}")
    public AjaxResponse deleteAddress(@PathVariable Long id) {
        utCustomerAddressService.deleteAddress(id);
        return AjaxResponse.success();
    }

    @SaCheckLogin
    @PutMapping("/update")
    public AjaxResponse updateAddress(@Validated @RequestBody AddressUpdateDTO addressUpdateDTO) {
        utCustomerAddressService.updateAddress(addressUpdateDTO);
        return AjaxResponse.success();
    }

    @SaCheckLogin
    @GetMapping("/list")
    public AjaxResponse getAddress() {
        List<CustomerAddressListItemVO> address = utCustomerAddressService.getAddress();
        return AjaxResponse.success(address);
    }

}
